﻿#{extends 'main.html' /} 
#{set title:'佳佳味点餐' /}
#{set 'moreScripts'}
	#{script src:'jquery.gchart.js', charset:'utf-8'  /}
#{/set}

<script language="javascript">
var var_date = new Date();
	if(var_date.getHours()>=13)
	{
		var_date.setTime(var_date.getTime() + (1000*3600*24));
	}

$(document).ready(
         function(){
			$('#submit_button').click(submitOrder);
			$("input[name='input_radio']:nth(0)").attr("checked","checked");
			$('#infors').load('@{ordersInfo}');
			$('#date_span').html(var_date);
		 });

function submitOrder()
{
	var postAction = #{jsAction @placeOrder(':user_name',':food_id') /}
	var userName = $.trim($('#input_username').val());
	var foodId = $("input[name='input_radio']:checked").val();
	if(userName == '')
	{
		alert("请输入用户名！");
		return;
	}
	var var_now = new Date();
	var var_deadLine = new Date(var_date.getTime());
	var_deadLine.setHours(10);
	var_deadLine.setMinutes(13);
	var_deadLine.setSeconds(0);
	var_deadLine.setMilliseconds(0);
	if(var_now >= var_deadLine)
	{
		alert("已超过截止时间，请联系hxu订餐。" );
		return;
	}
	$.post(postAction({user_name: userName, food_id: foodId }),function(data){
		if(data.result=="succ")
		{
			alert("'"+data.order.user.userName+"' 预定 '"+data.order.food.name+"' 成功");
			$('#infors').load('@{ordersInfo}');
		}
	}
	);
}
</script>
<h1>佳佳味点餐</h1>
<p class="note">请各位务必在10:00之前定餐，每天13点以后可以预定第二天午餐，程序还在测试中，有问题请Call 7464(李珂) 7468(徐浩)。</p>
<h2>
	<a>
	<span id="date_span" class="shortDateFormat">${w_username} %{out.print((java.text.DateFormat.getDateInstance()).format(new java.util.Date()));}%</span>点餐
	</a>
</h2>
<p>
	<div class="objectForm">
		<form id="myform" name="myform" method="post" action="#">
			<div class="crudField crud_text">
				<label for="input_username">姓名:</label>
				<input type="input" id="input_username" name="username" checked="false" value ="${user?.userName}" />
				<span class="crudHelp"></span>
			</div>
			<div class="crudField crud_text">
				<label for="food_list">点餐:</label>
				<div style="margin-left:120px;">
				<ul id="food_list" style="list-style:none outside none;" >
				#{list items:objects ,as:'food'}
					<li><input type="radio" name="input_radio" value="${food.id}"  size="50"/>${food.name}</li>
				#{/list}
				</ul>
				</div>
				<span class="crudHelp"></span>
			</div>
			<p class="crudButtons" style="margin-top: 0px; margin-bottom: 0px;">
				<input id="submit_button" type="button" name="" value="Save"/>
			</p>

		</form>
	</div>
</p>
<div id = "infors">
</div>

